﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Entity
{
    [Table("wms_basic_warehouse")]
    public class WarehouseEntity
    {
        [Key]
        public int warehouse_id { get; set; }
        public string warehouse_number { get; set; }
        public string warehouse_name { get; set; }
        public decimal warehouse_capacity { get; set; }
        public int organizations_id { get; set; }
        public int users_id { get; set; }
        public string warehouse_address { get; set; }
        public string default_warehouse { get; set; }
        public string sorting { get; set; }

        // 修复：改为字符串类型，与数据库一致
        public string warehouse_status { get; set; }
        public string warehouse_locked { get; set; }

        public string note { get; set; }
        public string create_by { get; set; }
        public DateTime create_time { get; set; }
        public string update_by { get; set; }
        public DateTime? update_time { get; set; }

        // 修复：改为字符串类型，与数据库一致
        public string is_delete { get; set; }

        public int LocationCount { get; set; }
    }

    public class WarehouseAddDTO
    {
        public string WarehouseNumber { get; set; }
        public string WarehouseName { get; set; }
        public decimal WarehouseCapacity { get; set; }
        public int OrgId { get; set; }
        public int ManagerId { get; set; }
        public string Phone { get; set; }
        public string Address { get; set; }
        public bool IsDefault { get; set; }
        public int Sorting { get; set; }
        public int Status { get; set; }
        public int Locked { get; set; }
        public string Note { get; set; }
        public List<int> SelectedLocationIds { get; set; }
        public List<StorageLocationAddDTO> NewLocations { get; set; } = new List<StorageLocationAddDTO>();
    }

    public class StorageLocationDTO
    {
        public string LocationNumber { get; set; }
        public string LocationName { get; set; }
        public decimal LocationCapacity { get; set; }
        public int LocationManager { get; set; } // 库位主管ID
        public int LocationSorting { get; set; }
        public int LocationStatus { get; set; }
        public string LocationNote { get; set; }
    }
    public class WarehouseStatusDTO
    {
        /// <summary>
        /// 状态值（与数据库字段warehouse_status对应）
        /// </summary>
        public string StatusValue { get; set; }

        /// <summary>
        /// 状态名称（如“启用”“停用”）
        /// </summary>
        public string StatusName { get; set; }
    }
    public class WarehouseDetailDTO
    {
        public int warehouse_id { get; set; } // 仓库ID
        public string warehouse_number { get; set; } // 仓库编号
        public string warehouse_name { get; set; } // 仓库名称
        public decimal warehouse_capacity { get; set; } // 仓库容量
        public string warehouse_address { get; set; } // 仓库地址
        public int organizations_id { get; set; } // 所属部门ID
        public int users_id { get; set; } // 仓库主管ID
        public int locationCount { get; set; } // 库位数量
        public string warehouse_status { get; set; } // 仓库状态（1-启用，0-停用，2-锁定）
        public string create_by { get; set; } // 创建人
        public DateTime? create_time { get; set; } // 创建时间
        public string update_by { get; set; } // 更新人
        public DateTime? update_time { get; set; } // 更新时间
        public string contact_phone { get; set; } // 联系电话（如果有）
        public string remark { get; set; } // 备注（如果有）
    }
    /// <summary>
    /// 仓库编辑DTO
    /// </summary>
    public class WarehouseEditDTO
    {
        /// <summary>
        /// 仓库ID（必须）
        /// </summary>
        [Required(ErrorMessage = "仓库ID不能为空")]
        public int WarehouseId { get; set; }

        /// <summary>
        /// 仓库编号（编辑时可修改，但需唯一）
        /// </summary>
        [Required(ErrorMessage = "仓库编号不能为空")]
        public string WarehouseNumber { get; set; }

        /// <summary>
        /// 仓库名称
        /// </summary>
        [Required(ErrorMessage = "仓库名称不能为空")]
        public string WarehouseName { get; set; }

        /// <summary>
        /// 仓库容量（m³）
        /// </summary>
        [Range(0.01, double.MaxValue, ErrorMessage = "仓库容量必须大于0")]
        public decimal WarehouseCapacity { get; set; }

        /// <summary>
        /// 所属部门ID
        /// </summary>
        [Range(1, int.MaxValue, ErrorMessage = "请选择库管部门")]
        public int OrgId { get; set; }

        /// <summary>
        /// 仓库主管ID
        /// </summary>
        [Range(1, int.MaxValue, ErrorMessage = "请选择仓库主管")]
        public int ManagerId { get; set; }

        /// <summary>
        /// 仓库地址
        /// </summary>
        public string Address { get; set; }

        /// <summary>
        /// 是否默认仓库
        /// </summary>
        public bool IsDefault { get; set; }

        /// <summary>
        /// 排序号
        /// </summary>
        public int Sorting { get; set; }

        /// <summary>
        /// 状态（0=停用，1=启用，2=锁定）
        /// </summary>
        public int Status { get; set; }

        /// <summary>
        /// 备注
        /// </summary>
        public string Note { get; set; }

        /// <summary>
        /// 关联的库位ID列表（编辑时可重新选择）
        /// </summary>
        [Required(ErrorMessage = "请至少选择一个库位")]
        public List<int> SelectedLocationIds { get; set; } = new List<int>();
        /// <summary>
        /// 同时新增的库位列表
        /// </summary>
        public List<StorageLocationAddDTO> NewLocations { get; set; } = new List<StorageLocationAddDTO>();
    }
}